<template>
    <div class="app-container calendar-list-container">
        <!-- 查询和其他操作 -->
        <div class="filter-container">
        <el-input clearable class="filter-item" style="width: 200px;" placeholder="活动序号" v-model="listQuery.activityId">
        </el-input>
        <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查询</el-button>
        <el-button class="filter-item" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button>
        </div>

        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" width="150px" label="序号" prop="id">
          </el-table-column>
          <el-table-column align="center" min-width="150px" label="活动序号" prop="activityId">
          </el-table-column>
          <el-table-column align="center" min-width="150px" label="会员号" prop="customerId">
          </el-table-column>
          <el-table-column align="center" min-width="100px" label="状态" prop="join">
              <template slot-scope="scope">
                  <span v-if="scope.row.join == 0">未加入</span>
                  <span v-if="scope.row.join == 1">已加入</span>
              </template>
          </el-table-column>       
          <el-table-column align="center" min-width="100px" label="真实姓名" prop="realName">
          </el-table-column>       
          <el-table-column align="center" min-width="100px" label="联系方式 " prop="contactWay">
              <template slot-scope="scope">
                  <span v-if="scope.row.contactWay == 0">微信</span>
                  <span v-if="scope.row.contactWay == 1">QQ</span>
                  <span v-if="scope.row.contactWay == 2">手机号</span>
              </template>
          </el-table-column>   
          <el-table-column align="center" min-width="200px" label="联系号码" prop="contactValue">
          </el-table-column>   
          <el-table-column align="center" min-width="200px" label="加入时间" prop="createTime">
          </el-table-column> 
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
            :page-sizes="[10,20,30,50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
        </div>
    </div>
</template>

<script>
import waves from '@/directive/waves' // 水波纹指令
import { listJoin } from '@/api/cms/activity/index'
import { mapGetters } from 'vuex'

export default {
  name: 'activity',
  directives: {
    waves
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 20,
        activityId: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  computed: {
    ...mapGetters([
      'elements',
      'name'
    ])
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    getList() {
      this.listLoading = true
      listJoin(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
    handleDownload() {
      this.downloadLoading = true
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = ['活动序号', '会员号', '状态', '真实姓名', '联系方式', '联系号码', '加入时间']
        const filterVal = ['activityId', 'customerId', 'join', 'realName', 'contactWay', 'contactValue', 'createTime']
        excel.export_json_to_excel2(tHeader, this.list, filterVal, '参加活动信息')
        this.downloadLoading = false
      })
    }
  }
}
</script>

<style>

</style>